#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
 struct ListNode 
 {
	int val;
	struct ListNode* next;
};
 struct ListNode* reverseList(struct ListNode* head)
 {
	 if (NULL == head)
	 {
		 return NULL;
	 }
	 
	 struct ListNode* p = head->next;
	 head->next = NULL;
	 struct ListNode* t = NULL;
	 while (p)
	 {
		 t = p;
		 p = p->next;
		 t->next = head;
		 head = t;
	 }
	 return head;
 }
 struct ListNode* AollocListNode(int x)
 {
	 struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));
	 newnode->next = NULL;
	 newnode->val = x;
	 return newnode;
 }
 void SListPushBack(struct ListNode** pphead, struct ListNode** ppend, int x)
 {
	 struct ListNode* p = AollocListNode(x);
	 if (*pphead == NULL)
	 {
		 *pphead = p;
		 *ppend = p;
	 }
	 else
	 {
		 (*ppend)->next = p;
		 *ppend = p;
	 }
 }
 void  SListPrint(struct ListNode* phead)
 {
	 while (phead)
	 {
		 printf("%d->", phead->val);
		 phead = phead->next;
	 }
	 printf("NULL\n");
 }
int main()
{
	struct ListNode* phead = NULL;
	struct ListNode* pend = NULL;
	SListPushBack(&phead, &pend, 1);
	SListPushBack(&phead, &pend, 2);
	SListPushBack(&phead, &pend, 3);
	SListPushBack(&phead, &pend, 4);
	SListPushBack(&phead, &pend, 5);

	phead = reverseList(phead);

	SListPrint(phead);
	free(phead);
	return 0;
}